//
//  SpriteBatchesAppDelegate.m
//  SpriteBatches
//
//  Created by Steffen Itterheim on 04.08.10.
//  Copyright Steffen Itterheim 2010. All rights reserved.
//

#import "SpriteBatchesAppDelegate.h"
#import "cocos2d.h"
#import "GameScene.h"
#import "MenuTest.h"

#import "SWList.h"

@implementation SpriteBatchesAppDelegate

@synthesize window;

- (void) applicationDidFinishLaunching:(UIApplication*)application
{
	// CC_DIRECTOR_INIT()
    ///»√≥Ã–Ú“ª÷±√¶◊≈£¨’‚—˘iphone∆¡ƒªæÕ≥£¡¡¡À
	[[UIApplication sharedApplication] setIdleTimerDisabled:YES]; 
	//
	// 1. Initializes an EAGLView with 0-bit depth format, and RGB565 render buffer
	// 2. EAGLView multiple touches: disabled
	// 3. creates a UIWindow, and assign it to the "window" var (it must already be declared)
	// 4. Parents EAGLView to the newly created window
	// 5. Creates Display Link Director
	// 5a. If it fails, it will use an NSTimer director
	// 6. It will try to run at 60 FPS
	// 7. Display FPS: NO
	// 8. Device orientation: Portrait
	// 9. Connects the director to the EAGLView
	//
	CC_DIRECTOR_INIT();
	
	// Obtain the shared director in order to...
	CCDirector *director = [CCDirector sharedDirector];
	
	// Sets landscape mode
	[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
	
    
    // Init the View Controller
	viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
	//viewController.wantsFullScreenLayout = YES;
    
    
	// Turn on display FPS
	[director setDisplayFPS:NO];
	
	// Turn on multiple touches
	EAGLView *view = [director openGLView];
    [view setMultipleTouchEnabled:YES];
    
	// make the OpenGLView a child of the view controller
	[viewController setView:view];
	
	// make the View Controller a child of the main window
	//[window addSubview: viewController.view];
    //[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
	window.rootViewController = viewController;
	

	
	// Default texture format for PNG/BMP/TIFF/JPEG/GIF images
	// It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
	// You can change anytime.
	[CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA4444];	
	
		
	//[[CCDirector sharedDirector] runWithScene: [GameScene scene]];
	
	CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
	//[frameCache addSpriteFramesWithFile:@"game-art.plist"];
    
    NSString * fish_name_plist=nil;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        fish_name_plist=@"gameEngineSpriteSheetDefault-hd.plist";
    }
    else{
        fish_name_plist=@"gameEngineSpriteSheetDefault.plist";
    }
    
	[frameCache addSpriteFramesWithFile:fish_name_plist];
	
	CCScene *scene = [CCScene node];
	
	CCLayer *layer = [Layer1 node];
	[scene addChild: layer z:0];
	
	//[[CCDirector sharedDirector] runWithScene: [HelloWorld scene]];
	[[CCDirector sharedDirector] runWithScene: scene];
    
    
    
    
    
    //获取软件列表
    SWList * aSWList=[SWList sharedInstance];
    [aSWList startThreadToGetList];
    
    
    //music on
    [GameMusicSetting setIsMusicOn:true];
    [GameMusicSetting playBackgroundMusic:@"xmas.mp3"];
}


- (void)applicationWillResignActive:(UIApplication *)application {
	[[CCDirector sharedDirector] pause];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
	[[CCDirector sharedDirector] resume];
}

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
	[[CCDirector sharedDirector] purgeCachedData];
}

-(void) applicationDidEnterBackground:(UIApplication*)application {
	[[CCDirector sharedDirector] stopAnimation];
}

-(void) applicationWillEnterForeground:(UIApplication*)application {
	[[CCDirector sharedDirector] startAnimation];
}

- (void)applicationWillTerminate:(UIApplication *)application {
	CC_DIRECTOR_END();
}

- (void)applicationSignificantTimeChange:(UIApplication *)application {
	[[CCDirector sharedDirector] setNextDeltaTimeZero:YES];
}

- (void)dealloc {
	[[CCDirector sharedDirector] release];
	[window release];
	[super dealloc];
}

@end
